*----------------------------------------------------------------------------------------------------------	* 
* RESEARCHERS:		Emtiaz Hritan, Tim Bruckner									   							*
* PROGRAMMED BY:	Emtiaz Hritan																			*
* DESCRIPTION:      The Politics of Birth: How Local Representation Shapes Maternal-Infant Outcomes				 						 	*
* CREATED:			Aug. 27, 2025																		   	*
* LAST MODIFIED:	Jan. 27, 2026													       					*
*----------------------------------------------------------------------------------------------------------	*

clear all
set more off
* Set local paths
* Set this local datapath equal to the folder location for data
	local datapath "C:\Users\name\Replication Files Politics of Birth\Data"
* Set this local outputpath equal to the folder location for outcome like tables
	local outputpath "C:\Users\name\Replication Files Politics of Birth\Outcome"



* Install necessary packages
ssc install reghdfe
ssc install ftools
ssc install grstyle, replace
ssc install palettes, replace
ssc install colrspace, replace
ssc install ppmlhdfe, replace 
ssc install jwdid, replace 
ssc install csdid, replace 
ssc install drdid, replace 
ssc install did_imputation, replace
ssc install frause, replace
frause mpdta.dta, clear
ssc install hdfe, replace 
ssc install event_plot, replace
ssc install addplot, replace

* First, we limit our outcome variables to the following:
*births_all
*deaths_neonat_all 
*births_ptb_all
*births_vptb_all
*births_eptb_all
*births_lbw_all
*births_vlbw_all
*births_csection_all
*births_periviable_all
*births_previsit_all

*births_HSP
*deaths_neonat_HSP
*births_ptb_HSP
*births_vptb_HSP
*births_eptb_HSP
*births_lbw_HSP
*births_vlbw_HSP
*births_csection_HSP
*births_periviable_HSP
*births_previsit_HSP

*births_NHB
*deaths_neonat_NHB
*births_ptb_NHB
*births_vptb_NHB
*births_eptb_NHB
*births_lbw_NHB
*births_vlbw_NHB
*births_csection_NHB
*births_periviable_NHB
*births_previsit_NHB

*births_NHW
*deaths_neonat_NHW
*births_ptb_NHW
*births_vptb_NHW
*births_eptb_NHW
*births_lbw_NHW
*births_vlbw_NHW
*births_csection_NHW
*births_periviable_NHW
*births_previsit_NHW




**************************************************************************************************
** Table 2: Impact of the First Female and Racial Minority Win on Perinatal Health Outcomes     **
**************************************************************************************************



clear all
*****************************Ever Female vs Never Female and Not Yet Treated Female ********************
*Import covariates file
use "`datapath'\all_covariates", clear 
* Election data ranges from 1989 to 2021; limit the covariates to this ranges
keep if inrange(year, 1995, 2019)
tempfile covariates
    save `covariates' 
	
*Import county health covariates file
use "`datapath'\county_covariates_health.dta", clear 
tempfile health_covariates
    save `health_covariates' 	
	
	
	
* Keep the counties in our sample 
clear all
use "`datapath'\county_election.dta"
keep county_fips  year_female year_black year_hispanic year_asian
duplicates drop county_fips, force
* Null out first-year vars outside the window of 1995-2019. WE also want at least one pre-treatment year inside the analysis window.
drop if (!missing(year_female)   & !inrange(year_female,   1996, 2019)) ///
  |    (!missing(year_black)     & !inrange(year_black,    1996, 2019)) ///
  |    (!missing(year_hispanic)  & !inrange(year_hispanic, 1996, 2019)) ///
  |    (!missing(year_asian)     & !inrange(year_asian,    1996, 2019))
sort county_fips
tempfile sample_county
    save `sample_county' 

* import perinatal file
use "`datapath'\county_year_birth_death.dta"	
merge m:1 county_fips using `sample_county' 
keep if _merge==3
drop _merge


* Merge it with county covariates

merge 1:1 county_fips year using `covariates'
keep if _merge==3
drop _merge

* Merge it with county health covariates

merge 1:1 county_fips year using `health_covariates'
keep if _merge==3
drop _merge


xtset county_fips year


*Build rates (guards for zero denominators)
gen imr                = 1000 * deaths_neonat_all  / births_all           if births_all>0   // per 1,000
gen ptb_rate           = 100  * births_ptb_all     / births_all           if births_all>0   // %
gen vptb_rate          = 100  * births_vptb_all    / births_all           if births_all>0   // %
gen eptb_rate          = 100  * births_eptb_all    / births_all           if births_all>0   // %
gen lbw_rate           = 100  * births_lbw_all     / births_all           if births_all>0   // %
gen vlbw_rate          = 100  * births_vlbw_all    / births_all           if births_all>0   // %
gen csection_rate      = 100  * births_csection_all/ births_all           if births_all>0   // %
gen periviable_rate    = 100  * births_periviable_all / births_all        if births_all>0   // %


gen imr_HSP                = 1000 * deaths_neonat_HSP  / births_HSP           if births_HSP>0   // per 1,000
gen ptb_rate_HSP           = 100  * births_ptb_HSP     / births_HSP           if births_HSP>0   // %
gen vptb_rate_HSP          = 100  * births_vptb_HSP    / births_HSP           if births_HSP>0   // %
gen eptb_rate_HSP          = 100  * births_eptb_HSP    / births_HSP           if births_HSP>0   // %
gen lbw_rate_HSP           = 100  * births_lbw_HSP     / births_HSP           if births_HSP>0   // %
gen vlbw_rate_HSP          = 100  * births_vlbw_HSP    / births_HSP           if births_HSP>0   // %
gen csection_rate_HSP      = 100  * births_csection_HSP/ births_HSP           if births_HSP>0   // %
gen periviable_rate_HSP    = 100  * births_periviable_HSP / births_HSP        if births_HSP>0   // %



gen imr_NHB                = 1000 * deaths_neonat_NHB  / births_NHB           if births_NHB>0   // per 1,000
gen ptb_rate_NHB           = 100  * births_ptb_NHB     / births_NHB           if births_NHB>0   // %
gen vptb_rate_NHB          = 100  * births_vptb_NHB    / births_NHB           if births_NHB>0   // %
gen eptb_rate_NHB          = 100  * births_eptb_NHB    / births_NHB           if births_NHB>0   // %
gen lbw_rate_NHB           = 100  * births_lbw_NHB     / births_NHB           if births_NHB>0   // %
gen vlbw_rate_NHB          = 100  * births_vlbw_NHB    / births_NHB           if births_NHB>0   // %
gen csection_rate_NHB      = 100  * births_csection_NHB / births_NHB           if births_NHB>0   // %
gen periviable_rate_NHB    = 100  * births_periviable_NHB / births_NHB        if births_NHB>0   // %


gen imr_NHW                = 1000 * deaths_neonat_NHW  / births_NHW           if births_NHW>0   // per 1,000
gen ptb_rate_NHW           = 100  * births_ptb_NHW     / births_NHW           if births_NHW>0   // %
gen vptb_rate_NHW          = 100  * births_vptb_NHW    / births_NHW           if births_NHW>0   // %
gen eptb_rate_NHW          = 100  * births_eptb_NHW    / births_NHW           if births_NHW>0   // %
gen lbw_rate_NHW           = 100  * births_lbw_NHW     / births_NHW           if births_NHW>0   // %
gen vlbw_rate_NHW          = 100  * births_vlbw_NHW    / births_NHW           if births_NHW>0   // %
gen csection_rate_NHW      = 100  * births_csection_NHW / births_NHW           if births_NHW>0   // %
gen periviable_rate_NHW    = 100  * births_periviable_NHW / births_NHW        if births_NHW>0   // %



*-------------------------------------------
* 3) Variables that remain as MEANS
*    gestation (weeks) and prenatal visits
* 
*-------------------------------------------
label var births_gestation_all "Mean gestational age (weeks, All)"
label var births_gestation_HSP "Mean gestational age (weeks, HSP)"
label var births_gestation_NHB "Mean gestational age (weeks, NHB)"
label var births_gestation_NHW "Mean gestational age (weeks, NHW)"

label var births_previsit_all  "Mean prenatal visits (All)"
label var births_previsit_HSP  "Mean prenatal visits (HSP)"
label var births_previsit_NHB  "Mean prenatal visits (NHB)"
label var births_previsit_NHW  "Mean prenatal visits (NHW)"



cd "`datapath'"
save final.dta, replace
clear all
************************************************************
* Impact of female candidate win on birth outcomes 
************************************************************
use "`datapath'\final.dta"

* Setting up a relative path to store the tables
cd "`outputpath'"

* Traditional Two-way Fixed Effect model

	
* 1-year induction
gen treat_female = year >= year_female + 1 if !missing(year_female)
replace treat_female = 0 if missing(treat_female)	

	
* Let's drop counties with low births 
drop if births_all < 100	
	
*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*
local outcomes_all  imr ptb_rate vptb_rate eptb_rate lbw_rate vlbw_rate csection_rate periviable_rate ///
                    births_gestation_all births_previsit_all infant_mortality_rate

local outcomes_NHW  imr_NHW ptb_rate_NHW vptb_rate_NHW eptb_rate_NHW lbw_rate_NHW vlbw_rate_NHW ///
                    csection_rate_NHW periviable_rate_NHW births_gestation_NHW births_previsit_NHW infant_mortality_NHW

local outcomes_NHB  imr_NHB ptb_rate_NHB vptb_rate_NHB eptb_rate_NHB lbw_rate_NHB vlbw_rate_NHB ///
                    csection_rate_NHB periviable_rate_NHB births_gestation_NHB births_previsit_NHB infant_mortality_NHB

local outcomes_HSP  imr_HSP ptb_rate_HSP vptb_rate_HSP eptb_rate_HSP lbw_rate_HSP vlbw_rate_HSP ///
                    csection_rate_HSP periviable_rate_HSP births_gestation_HSP births_previsit_HSP infant_mortality_HSP
					
*-------------------------------------------*
* Define covariates lists
*-------------------------------------------*
* County covariates					
*LaborForce Employed Unemployed UnemploymentRate pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus share_under5 share_under25 share_25_34 share_35plus share_65plus earnings transfers 


* County level birth outcome covariates
*share_mult share_male share_edu_ltHS share_edu_HS share_edu_somecol share_edu_ba share_edu_grad share_age_lt20 share_age_20_24 share_age_25_34 share_age_35p share_par0 share_par1 share_par2p

* variables: earnings, transfers, pop_total, UnemploymentRate

* Per-capita and logs
gen earn_pc = earnings/pop_total if pop_total>0
gen trans_pc = transfers/pop_total if pop_total>0
gen l_earn_pc = ln(earn_pc) if earn_pc>0
gen l_trans_pc = ln(trans_pc) if trans_pc>0

local macro_lags L1.UnemploymentRate L1.l_earn_pc L1.l_trans_pc


* After xtset county_fips year, generate lags for the shares you built earlier
foreach v in share_mult share_male ///
    share_edu_ltHS share_edu_ba share_edu_grad ///
    share_age_25_34 share_age_35p ///
    share_par0 share_par2p {
    capture gen L1_`v' = L.`v'
}

local covariates_health L1_share_mult L1_share_male ///
    L1_share_edu_ltHS L1_share_edu_ba L1_share_edu_grad ///
    L1_share_age_25_34 L1_share_age_35p ///
    L1_share_par0 L1_share_par2p					
					

*-------------------------------------------*
* Loop: All births
*-------------------------------------------*
eststo clear
foreach y of local outcomes_all {
    eststo: reghdfe `y' treat_female `covariates_health' `macro_lags' [aw=births_all], absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_all_female_covariates.csv, b(3) se(3) r2 replace
eststo clear

************************************************************
* Impact of black candidate win on birth outcomes 
************************************************************

clear all 
use "`datapath'\final.dta"
	
* 1-year induction
gen treat_black = year >= year_black + 1 if !missing(year_black)
replace treat_black = 0 if missing(treat_black)	

* Let's drop counties with low births and low NH Black births
drop if births_all < 100

*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*
local outcomes_all  imr ptb_rate vptb_rate eptb_rate lbw_rate vlbw_rate csection_rate periviable_rate ///
                    births_gestation_all births_previsit_all infant_mortality_rate

local outcomes_NHW  imr_NHW ptb_rate_NHW vptb_rate_NHW eptb_rate_NHW lbw_rate_NHW vlbw_rate_NHW ///
                    csection_rate_NHW periviable_rate_NHW births_gestation_NHW births_previsit_NHW infant_mortality_NHW

local outcomes_NHB  imr_NHB ptb_rate_NHB vptb_rate_NHB eptb_rate_NHB lbw_rate_NHB vlbw_rate_NHB ///
                    csection_rate_NHB periviable_rate_NHB births_gestation_NHB births_previsit_NHB infant_mortality_NHB

local outcomes_HSP  imr_HSP ptb_rate_HSP vptb_rate_HSP eptb_rate_HSP lbw_rate_HSP vlbw_rate_HSP ///
                    csection_rate_HSP periviable_rate_HSP births_gestation_HSP births_previsit_HSP infant_mortality_HSP

					
					
*-------------------------------------------*
* Define covariates lists
*-------------------------------------------*
* County covariates					
*LaborForce Employed Unemployed UnemploymentRate pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus share_under5 share_under25 share_25_34 share_35plus share_65plus earnings transfers 


* County level birth outcome covariates
*share_mult share_male share_edu_ltHS share_edu_HS share_edu_somecol share_edu_ba share_edu_grad share_age_lt20 share_age_20_24 share_age_25_34 share_age_35p share_par0 share_par1 share_par2p

* variables: earnings, transfers, pop_total, UnemploymentRate

* Per-capita and logs
gen earn_pc = earnings/pop_total if pop_total>0
gen trans_pc = transfers/pop_total if pop_total>0
gen l_earn_pc = ln(earn_pc) if earn_pc>0
gen l_trans_pc = ln(trans_pc) if trans_pc>0

local macro_lags L1.UnemploymentRate L1.l_earn_pc L1.l_trans_pc


* After xtset county_fips year, generate lags for the shares you built earlier
foreach v in share_mult share_male ///
    share_edu_ltHS share_edu_ba share_edu_grad ///
    share_age_25_34 share_age_35p ///
    share_par0 share_par2p {
    capture gen L1_`v' = L.`v'
}

local covariates_health L1_share_mult L1_share_male ///
    L1_share_edu_ltHS L1_share_edu_ba L1_share_edu_grad ///
    L1_share_age_25_34 L1_share_age_35p ///
    L1_share_par0 L1_share_par2p
			
* Loop: All births

eststo clear
foreach y of local outcomes_all {
    eststo: reghdfe `y' treat_black `covariates_health' `macro_lags' [aw=births_all], absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_all_black_covariates.csv, b(3) se(3) r2 replace
eststo clear


************************************************************
* Impact of hispanic candidate win on birth outcomes 
************************************************************

clear all 
use "`datapath'\final.dta"
	
* 1-year induction
gen treat_hispanic = year >= year_hispanic + 1 if !missing(year_hispanic)
replace treat_hispanic = 0 if missing(treat_hispanic)

* Let's drop counties with low births and low NH Black births
drop if births_all < 100

*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*
local outcomes_all  imr ptb_rate vptb_rate eptb_rate lbw_rate vlbw_rate csection_rate periviable_rate ///
                    births_gestation_all births_previsit_all infant_mortality_rate

local outcomes_NHW  imr_NHW ptb_rate_NHW vptb_rate_NHW eptb_rate_NHW lbw_rate_NHW vlbw_rate_NHW ///
                    csection_rate_NHW periviable_rate_NHW births_gestation_NHW births_previsit_NHW infant_mortality_NHW

local outcomes_NHB  imr_NHB ptb_rate_NHB vptb_rate_NHB eptb_rate_NHB lbw_rate_NHB vlbw_rate_NHB ///
                    csection_rate_NHB periviable_rate_NHB births_gestation_NHB births_previsit_NHB infant_mortality_NHB

local outcomes_HSP  imr_HSP ptb_rate_HSP vptb_rate_HSP eptb_rate_HSP lbw_rate_HSP vlbw_rate_HSP ///
                    csection_rate_HSP periviable_rate_HSP births_gestation_HSP births_previsit_HSP infant_mortality_HSP

					
					
*-------------------------------------------*
* Define covariates lists
*-------------------------------------------*
* County covariates					
*LaborForce Employed Unemployed UnemploymentRate pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus share_under5 share_under25 share_25_34 share_35plus share_65plus earnings transfers 


* County level birth outcome covariates
*share_mult share_male share_edu_ltHS share_edu_HS share_edu_somecol share_edu_ba share_edu_grad share_age_lt20 share_age_20_24 share_age_25_34 share_age_35p share_par0 share_par1 share_par2p

* variables: earnings, transfers, pop_total, UnemploymentRate

* Per-capita and logs
gen earn_pc = earnings/pop_total if pop_total>0
gen trans_pc = transfers/pop_total if pop_total>0
gen l_earn_pc = ln(earn_pc) if earn_pc>0
gen l_trans_pc = ln(trans_pc) if trans_pc>0

local macro_lags L1.UnemploymentRate L1.l_earn_pc L1.l_trans_pc


* After xtset county_fips year, generate lags for the shares you built earlier
foreach v in share_mult share_male ///
    share_edu_ltHS share_edu_ba share_edu_grad ///
    share_age_25_34 share_age_35p ///
    share_par0 share_par2p {
    capture gen L1_`v' = L.`v'
}

local covariates_health L1_share_mult L1_share_male ///
    L1_share_edu_ltHS L1_share_edu_ba L1_share_edu_grad ///
    L1_share_age_25_34 L1_share_age_35p ///
    L1_share_par0 L1_share_par2p
			
* Loop: All births

eststo clear
foreach y of local outcomes_all {
    eststo: reghdfe `y' treat_hispanic `covariates_health' `macro_lags' [aw=births_all], absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_all_hispanic_covariates.csv, b(3) se(3) r2 replace
eststo clear


************************************************************
* Impact of asian candidate win on birth outcomes 
************************************************************

clear all 
use "`datapath'\final.dta"
	
* 1-year induction
gen treat_asian = year >= year_asian + 1 if !missing(year_asian)
replace treat_asian = 0 if missing(treat_asian)

* Let's drop counties with low births and low NH Black births
drop if births_all < 100

*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*
local outcomes_all  imr ptb_rate vptb_rate eptb_rate lbw_rate vlbw_rate csection_rate periviable_rate ///
                    births_gestation_all births_previsit_all infant_mortality_rate

local outcomes_NHW  imr_NHW ptb_rate_NHW vptb_rate_NHW eptb_rate_NHW lbw_rate_NHW vlbw_rate_NHW ///
                    csection_rate_NHW periviable_rate_NHW births_gestation_NHW births_previsit_NHW infant_mortality_NHW

local outcomes_NHB  imr_NHB ptb_rate_NHB vptb_rate_NHB eptb_rate_NHB lbw_rate_NHB vlbw_rate_NHB ///
                    csection_rate_NHB periviable_rate_NHB births_gestation_NHB births_previsit_NHB infant_mortality_NHB

local outcomes_HSP  imr_HSP ptb_rate_HSP vptb_rate_HSP eptb_rate_HSP lbw_rate_HSP vlbw_rate_HSP ///
                    csection_rate_HSP periviable_rate_HSP births_gestation_HSP births_previsit_HSP infant_mortality_HSP

					
					
*-------------------------------------------*
* Define covariates lists
*-------------------------------------------*
* County covariates					
*LaborForce Employed Unemployed UnemploymentRate pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus share_under5 share_under25 share_25_34 share_35plus share_65plus earnings transfers 


* County level birth outcome covariates
*share_mult share_male share_edu_ltHS share_edu_HS share_edu_somecol share_edu_ba share_edu_grad share_age_lt20 share_age_20_24 share_age_25_34 share_age_35p share_par0 share_par1 share_par2p

* variables: earnings, transfers, pop_total, UnemploymentRate

* Per-capita and logs
gen earn_pc = earnings/pop_total if pop_total>0
gen trans_pc = transfers/pop_total if pop_total>0
gen l_earn_pc = ln(earn_pc) if earn_pc>0
gen l_trans_pc = ln(trans_pc) if trans_pc>0

local macro_lags L1.UnemploymentRate L1.l_earn_pc L1.l_trans_pc


* After xtset county_fips year, generate lags for the shares you built earlier
foreach v in share_mult share_male ///
    share_edu_ltHS share_edu_ba share_edu_grad ///
    share_age_25_34 share_age_35p ///
    share_par0 share_par2p {
    capture gen L1_`v' = L.`v'
}

local covariates_health L1_share_mult L1_share_male ///
    L1_share_edu_ltHS L1_share_edu_ba L1_share_edu_grad ///
    L1_share_age_25_34 L1_share_age_35p ///
    L1_share_par0 L1_share_par2p
			
* Loop: All births

eststo clear
foreach y of local outcomes_all {
    eststo: reghdfe `y' treat_asian `covariates_health' `macro_lags' [aw=births_all], absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_all_asian_covariates.csv, b(3) se(3) r2 replace
eststo clear


*--------------------------------------------------------------------------
* END
*--------------------------------------------------------------------------



*---------------------------------------------------------------------------------------------------------------
* Table 3: Impact of the First Black Candidate Win on Perinatal Health Outcomes of Non-Hispanic Black Mothers **
*---------------------------------------------------------------------------------------------------------------


*****************************Ever Black vs Never Black and Not Yet Treated Black ********************

********************************************************************************
* Traditional Two-way Fixed Effect model (without controls + 100 baths)
*
********************************************************************************
clear all 
use "`datapath'\final.dta"
	
* 1-year induction
gen treat_black = year >= year_black + 1 if !missing(year_black)
replace treat_black = 0 if missing(treat_black)	

* Let's drop counties with low births and low NH Black births
drop if births_all < 100
drop if births_NHB < 100	

	
*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*

local outcomes_NHB  imr_NHB ptb_rate_NHB vptb_rate_NHB eptb_rate_NHB lbw_rate_NHB vlbw_rate_NHB ///
                    csection_rate_NHB periviable_rate_NHB births_gestation_NHB births_previsit_NHB infant_mortality_NHB


*-------------------------------------------*
* Loop: NHB births
*-------------------------------------------*
eststo clear
foreach y of local outcomes_NHB {
    eststo: reghdfe `y' treat_black [aw=births_NHB], absorb(county_fips year) vce(cluster county_fips)
}
esttab using results_NHB_black_100.csv, b(3) se(3) r2 replace
eststo clear

	
	
********************************************************************************
* Traditional Two-way Fixed Effect model (Controls + 100 baths)
*
********************************************************************************
clear all 
use "`datapath'\final.dta"
	
* 1-year induction
gen treat_black = year >= year_black + 1 if !missing(year_black)
replace treat_black = 0 if missing(treat_black)	

* Let's drop counties with low births and low NH Black births
drop if births_all < 100
drop if births_NHB < 100	

*-------------------------------------------*
* Define outcome lists
*-------------------------------------------*
local outcomes_NHB  imr_NHB ptb_rate_NHB vptb_rate_NHB eptb_rate_NHB lbw_rate_NHB vlbw_rate_NHB ///
                    csection_rate_NHB periviable_rate_NHB births_gestation_NHB births_previsit_NHB infant_mortality_NHB
										
*-------------------------------------------*
* Define covariates lists
*-------------------------------------------*
* County covariates					
*LaborForce Employed Unemployed UnemploymentRate pop_total pop_male pop_female pop_white pop_black pop_ai_an pop_asian pop_hispanic pop_nonhispanic pop_under5 pop_under25 pop_25_34 pop_35plus pop_65plus share_under5 share_under25 share_25_34 share_35plus share_65plus earnings transfers 


* County level birth outcome covariates
*share_mult share_male share_edu_ltHS share_edu_HS share_edu_somecol share_edu_ba share_edu_grad share_age_lt20 share_age_20_24 share_age_25_34 share_age_35p share_par0 share_par1 share_par2p

* variables: earnings, transfers, pop_total, UnemploymentRate

* Per-capita and logs
gen earn_pc = earnings/pop_total if pop_total>0
gen trans_pc = transfers/pop_total if pop_total>0
gen l_earn_pc = ln(earn_pc) if earn_pc>0
gen l_trans_pc = ln(trans_pc) if trans_pc>0

local macro_lags L1.UnemploymentRate L1.l_earn_pc L1.l_trans_pc


* After xtset county_fips year, generate lags for the shares you built earlier
foreach v in share_mult share_male ///
    share_edu_ltHS share_edu_ba share_edu_grad ///
    share_age_25_34 share_age_35p ///
    share_par0 share_par2p {
    capture gen L1_`v' = L.`v'
}

local covariates_health L1_share_mult L1_share_male ///
    L1_share_edu_ltHS L1_share_edu_ba L1_share_edu_grad ///
    L1_share_age_25_34 L1_share_age_35p ///
    L1_share_par0 L1_share_par2p


*-------------------------------------------*
* Loop: NHB births
*-------------------------------------------*
eststo clear
foreach y of local outcomes_NHB {
    eststo: reghdfe `y' treat_black `covariates_health' `macro_lags' [aw=births_NHB], absorb(county_fips year) vce(cluster county_fips)
}
esttab using NHB_black_covariates.csv, b(3) se(3) r2 replace
eststo clear


*--------------------------------------------------------------------------
* END
*--------------------------------------------------------------------------
